package main


import (
    "fmt"
)


type treeNode struct {
    value int
    left, right *treeNode
}


func createTreeNode(Value int) *treeNode {
    return &treeNode{value: Value}
}


func (node treeNode) Print() {
    fmt.Printf("%d ", node.value)
}


func (node *treeNode) setValue(Value int) {
    if node == nil {
        fmt.Sprintf("node is nil")
        return 
    }

    node.value = Value
}


func (node *treeNode) traverse() {
    node.TraverseFunc(func(n *treeNode){
        n.Print()
    })
}


func (node *treeNode) TraverseFunc(f func(*treeNode)) {
    if node == nil {
        return
    }

    node.left.TraverseFunc(f)
    f(node)
    node.right.TraverseFunc(f)
}


func main(){
    var node treeNode
    
    node = treeNode{value: 1}
    node.left = createTreeNode(2)
    node.right = createTreeNode(3)

    node.traverse()


}

